package com.example.supernote.ui.components

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

/**
 * 显示进度条
 *
 * @param text 进度条文本，默认为空
 * @param shape 进度条形状，["circle", "line"]，默认为 "circle"
 * @param method 进度条模式，有限和无限，默认是无限
 * @param progress 当进度条模式为有限时的当前进度，[0.0, 1.0]
 */
@Composable
fun UniformProgressBar(
    text: String = "",
    shape: String = "circle",
    method: String = "infinite",
    progress: Float = 0f
) {
    if (shape == "circle") {
        Box(
            contentAlignment = Alignment.Center
        ) {
            if (method == "infinite")
                CircularProgressIndicator(
                    modifier = Modifier
                        .size(72.dp)
                        .align(Alignment.Center),
                )
            else {
                Row {
                    CircularProgressIndicator(
                        progress = { progress },
                        modifier = Modifier
                            .size(72.dp)
                    )
                    Spacer(modifier = Modifier.width(5.dp))
                    Text("${(progress * 100).toInt()}%")
                }
            }
            Text(
                modifier = Modifier
                    .align(Alignment.Center),
                text = text
            )
        }
    } else {
        Column(
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            if (method == "infinite") LinearProgressIndicator()
            else {
                Row(
                    verticalAlignment = Alignment.CenterVertically
                ) {
                    LinearProgressIndicator(progress = { progress })
                    Spacer(modifier = Modifier.width(5.dp))
                    Text("${(progress * 100).toInt()}%")
                }
            }
            Text(text)
        }
    }
}